import Mock from 'mockjs'

const Random = Mock.Random

// 登录
Mock.mock('/api/login', 'post', (option) => {
	let {
		username,
		password
	} = JSON.parse(option.body)
	let b = (username === 'admin' && password === 'admin')
	return {
		success: true,
		"result": b
	}
})

// 用户数据
const userData = () => {
	let users = []
	for (let i = 0; i < 10; i++) {
		let user = {
			'id': i + 1,
			'date': Random.date('yyyy-MM-dd'),
			'name': Random.cname(),
			'address': Mock.mock('@county(true)'),
			'phone': Mock.mock(/^1[0-9]{10}$/),
			'status': Random.integer(0, 1)
		}
		users.push(user)
	}
	return users
}

Mock.mock('/api/users', {success:true,result:{curPage:1,pageSize:10,content:userData}})

//menu data
Mock.mock('/api/menus', {success:true,result:[
	{
        lable: '主页',
        icon: 'el-icon-location',
        index: '0',
        path: '/console'
    },
	{
        lable: '用户',
        icon: 'el-icon-menu',
        index: '1',
        path: '/users'
    },
	{
        lable: '文章',
        icon: 'el-icon-document',
        index: '2',
        path: '/articles'
    },
	{
        lable: '设置',
        icon: 'el-icon-setting',
        index: '3',
        path: '/setting',
        children: [{
            lable: '基本资料',
			icon:'el-icon-setting',
            index: '3-1',
            path: '/profile',
        }, {
            lable: '修改密码',
			icon:'el-icon-setting',
            index: '3-2',
            path: '/password',
        }]
    },
	{
        lable: '图表',
        icon: 'el-icon-share',
        index: '4',
        path: '/echarts'
    }
]})

// 文章数据
const articleData = () => {
	let articles = []
	for (let i = 0; i < 20; i++) {
		let article = {
			'id': i + 1,
			'date': Random.date('yyyy-MM-dd'),
			'title': Random.csentence(),
			'author': Random.cname(),
			'content': Random.csentence(),
			'status': Random.integer(0, 1)
		}
		articles.push(article)
	}
	return articles
}
Mock.mock('/api/articles', articleData)
